package com.example.grpc.client.helloworld;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.StatusRuntimeException;
import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;

public class GreeterClient {
    public static void main(String[] args) {
        ManagedChannel channel =  ManagedChannelBuilder.forAddress("172.16.36.63",29080)
                .usePlaintext()
                .build();

        GreeterGrpc.GreeterBlockingStub blockingStub = GreeterGrpc.newBlockingStub(channel);

        HelloRequest request = HelloRequest.newBuilder().setName("weiwei").build();
        HelloReply response;
        try{
            response = blockingStub.sayHello(request);
        } catch (StatusRuntimeException e)
        {
            System.out.println("RPC failed: {}" + e.getStatus());
            return;
        }
        System.out.println("Message from gRPC-Server: "+response.getMessage());
    }

}
